package o;

import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.hms.framework.common.ContainerUtils;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class BaseRequest {
    protected static final String END_FLAG = "_";
    private int cacheExpiredTime = 0;
    private String cacheID;
    private String file;
    private Map<String, String> fileMap;
    private String fileParamName;
    private String host;
    private String method_;
    private o.cvu.RequestBodyType reqContentType = o.cvu.RequestBodyType.URI;
    private String requestId;
    private o.cvu.RequestStrategy requestType = o.cvu.RequestStrategy.REQUEST_NETWORK;
    private String storeApi;
    public String targetServer = "server.store";
    private String url;
    private String ver_ = cfv.VER_NUMBER;

    public enum RequestBodyType {
        FILE,
        URI,
        FORM
    }

    public enum RequestStrategy {
        REQUEST_CACHE_FIRST,
        REQUEST_CACHE,
        REQUEST_NETWORK,
        REQUEST_NETWORK_REF_CACHE,
        REQUEST_REF_CACHE
    }

    public static String getCacheID(BaseRequest o_cvu) {
        return o_cvu.getCacheID();
    }

    public static o.cvu.RequestStrategy getRequestType(BaseRequest o_cvu) {
        return o_cvu.getRequestType();
    }

    public static String getMethod_(BaseRequest o_cvu) {
        return o_cvu.getMethod_();
    }

    public static String genBody(BaseRequest o_cvu, boolean z) throws IllegalAccessException, IllegalArgumentException {
        return o_cvu.genBody(z);
    }

    public static String getReqUrl(BaseRequest o_cvu) {
        return o_cvu.getReqUrl();
    }

    public static String getFileParamName(BaseRequest o_cvu) {
        return o_cvu.getFileParamName();
    }

    public static String getFile(BaseRequest o_cvu) {
        return o_cvu.getFile();
    }

    public static int getCacheExpiredTime(BaseRequest o_cvu) {
        return o_cvu.getCacheExpiredTime();
    }

    public static o.cvu.RequestBodyType getReqContentType(BaseRequest o_cvu) {
        return o_cvu.getReqContentType();
    }

    protected String genBody(boolean z) throws IllegalAccessException, IllegalArgumentException {
        if (!z) {
            onSetValue();
        }
        Map param = getParam();
        String[] strArr = new String[param.size()];
        param.keySet().toArray(strArr);
        Arrays.sort(strArr);
        StringBuilder stringBuilder = new StringBuilder();
        int length = strArr.length;
        for (int i = 0; i < length; i++) {
            String value = getValue((Field) param.get(strArr[i]), z);
            if (value != null) {
                stringBuilder.append(strArr[i]).append(ContainerUtils.KEY_VALUE_DELIMITER).append(dof.ˏ(value)).append(ContainerUtils.FIELD_DELIMITER);
            }
        }
        int length2 = stringBuilder.length();
        if (length2 > 0 && stringBuilder.charAt(length2 - 1) == '&') {
            stringBuilder.deleteCharAt(length2 - 1);
        }
        return stringBuilder.toString();
    }

    protected void onSetValue() {
    }

    private String getReqUrl() {
        if ("server.store".equals(this.targetServer) || "server.uc".equals(this.targetServer)) {
            return this.url + "clientApi";
        }
        return this.url + this.storeApi;
    }

    private Map<String, Field> getParam() {
        Map<String, Field> hashMap = new HashMap();
        Field[] ˊ = dob.ˊ(getClass());
        int length = "_".length();
        for (Field field : ˊ) {
            field.setAccessible(true);
            String name = field.getName();
            if (name.endsWith("_")) {
                hashMap.put(name.substring(0, name.length() - length), field);
            }
        }
        return hashMap;
    }

    protected String getValue(Field field, boolean z) throws IllegalAccessException, IllegalArgumentException {
        Object obj = field.get(this);
        if (obj != null && (obj instanceof JsonBean)) {
            StringBuilder stringBuilder = new StringBuilder();
            if (!z) {
                ((JsonBean) obj).toJson(stringBuilder);
                return stringBuilder.toString();
            } else if (JsonBean.isFieldPrivacy(field)) {
                return "****";
            } else {
                if (!JsonBean.isFieldCanPrint(field)) {
                    return "*";
                }
                ((JsonBean) obj).toFilterJson(stringBuilder);
                return stringBuilder.toString();
            }
        } else if (obj == null) {
            return null;
        } else {
            if (z) {
                if (JsonBean.isFieldPrivacy(field)) {
                    obj = "****";
                } else if (!JsonBean.isFieldCanPrint(field)) {
                    obj = "*";
                }
            }
            return String.valueOf(obj);
        }
    }

    public String toString() {
        return "RequestBean [method_=" + this.method_ + ", ver_=" + this.ver_ + ", requestType=" + this.requestType + ", cacheExpiredTime=" + String.valueOf(this.cacheExpiredTime) + "]";
    }

    public String getCacheID() {
        return this.cacheID;
    }

    public void setCacheID(String str) {
        this.cacheID = str;
    }

    public String getStoreApi() {
        return this.storeApi;
    }

    public void setStoreApi(String str) {
        this.storeApi = str;
    }

    public String getMethod_() {
        return this.method_;
    }

    public void setMethod_(String str) {
        this.method_ = str;
    }

    public String getVer_() {
        return this.ver_;
    }

    public void setVer_(String str) {
        this.ver_ = str;
    }

    public o.cvu.RequestStrategy getRequestType() {
        return this.requestType;
    }

    public void setRequestType(o.cvu.RequestStrategy cVar) {
        this.requestType = cVar;
    }

    public int getCacheExpiredTime() {
        return this.cacheExpiredTime;
    }

    public void setCacheExpiredTime(int i) {
        this.cacheExpiredTime = i;
    }

    public String getUrl() {
        return this.url;
    }

    public void setUrl(String str) {
        this.url = str;
    }

    public String getHost() {
        return this.host;
    }

    public void setHost(String str) {
        this.host = str;
    }

    public o.cvu.RequestBodyType getReqContentType() {
        return this.reqContentType;
    }

    public void setReqContentType(o.cvu.RequestBodyType bVar) {
        this.reqContentType = bVar;
    }

    public String getFile() {
        return this.file;
    }

    public void setFile(String str) {
        this.file = str;
    }

    public String getFileParamName() {
        return this.fileParamName;
    }

    public void setFileParamName(String str) {
        this.fileParamName = str;
    }

    public Map<String, String> getFileMap() {
        return this.fileMap;
    }

    public void setFileMap(Map<String, String> map) {
        this.fileMap = map;
    }

    public String getRequestId() {
        return this.requestId;
    }

    public void setRequestId(String str) {
        this.requestId = str;
    }
}
